home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / uucp / AM114src.lha / client.c < prev    next >
C/C++ Source or Header  |  1992-04-29  |  6KB  |  322 lines

  1. /*
  2.  *
  3.  *  AM --- AmigaMail
  4.  *  (C) 1991, 1992 by Christian Riede
  5.  *
  6.  *  AM is distributed in the hope that it will be useful, but WITHOUT ANY
  7.  *  WARRANTY.  No author or distributor accepts responsibility to anyone
  8.  *  for the consequences of using it or for whether it serves any
  9.  *  particular purpose or works at all, unless he says so in writing.
  10.  *  Refer to the GNU General Public License, Version 1, for full details.
  11.  *  
  12.  *  Everyone is granted permission to copy, modify and redistribute AM,
  13.  *  but only under the conditions described in the GNU General Public
  14.  *  License, Version 1.  A copy of this license is supposed to have been 
  15.  *  given to you along with AM so you can know your rights and responsi-
  16.  *  bilities.  It should be in a file named COPYING.  Among other things,
  17.  *  the copyright notice and this notice must be preserved on all copies.
  18.  *
  19.  *  
  20.  *
  21.  */
  22.  
  23. #include "am.h"
  24.  
  25. struct MsgPort *ServerPort;
  26.  
  27. struct AMMessage *AskServer(struct AMMessage *Msg)
  28. {
  29.     struct AMMessage *Return;
  30.     struct MsgPort *ClientPort;
  31.  
  32.     Return = 0;
  33.  
  34.     /* server running ?*/
  35.     if (ServerPort)
  36.     {
  37.         /* to be reentrant we must create our own port */
  38.         if (!(ClientPort = CreatePort(0,0)))
  39.             return(0);
  40.  
  41.         Msg->AMMsg.mn_ReplyPort = ClientPort;
  42.  
  43.         /* give him the message */
  44.         PutMsg(ServerPort,(struct Message *)Msg);
  45.  
  46.         /* receive reply */    
  47.         /* since all requests are done syncronously */
  48.         /* the first message must be the reply to our request */
  49.         if (!(Return = (struct AMMessage *)GetMsg(ClientPort)))
  50.         {
  51.             /* wait for reply */
  52.             WaitPort(ClientPort);
  53.  
  54.             /* return the replied message */
  55.             Return = (struct AMMessage *)GetMsg(ClientPort);
  56.         }
  57.         DeletePort(ClientPort);
  58.     }
  59.  
  60.     return(Return);
  61. }
  62.  
  63.  
  64. int KillServer(void)
  65. {
  66.     struct AMMessage *Msg;
  67.     int ret;
  68.  
  69.     if (!(Msg = AllocAMMsg()))
  70.         return(FALSE);
  71.  
  72.     Msg->Action = ACT_DIE;
  73.  
  74.     AskServer(Msg); /* don't care for results */
  75.  
  76.     ret = Msg->Number;
  77.  
  78.     FreeMem(Msg,sizeof(struct AMMessage));
  79.     
  80.     return(ret);
  81. }
  82.  
  83.  
  84. int LockContents(void)
  85. {
  86.     struct AMMessage *Msg;
  87.     int ret;
  88.  
  89.     if (!(Msg = AllocAMMsg()))
  90.         return(FALSE);
  91.  
  92.     Msg->Action = ACT_LOCKCONTENTS;
  93.     Msg->Username = Username;
  94.  
  95.     AskServer(Msg); /* don't care for results */
  96.     ret = Msg->Number;
  97.  
  98.     FreeMem(Msg,sizeof(struct AMMessage));
  99.  
  100.     return(ret);
  101. }
  102.  
  103. void UnLockContents(void)
  104. {
  105.     struct AMMessage *Msg;
  106.  
  107.     if (!(Msg = AllocAMMsg()))
  108.         return;
  109.  
  110.     Msg->Action = ACT_UNLOCKCONTENTS;
  111.     Msg->Username = Username;
  112.  
  113.     AskServer(Msg); /* don't care for results */
  114.  
  115.     FreeMem(Msg,sizeof(struct AMMessage));
  116. }
  117.  
  118. int GetContents(struct List *Mailbox)
  119. {
  120.     struct AMMessage *Msg;
  121.     int ret;
  122.  
  123.     if (!(Msg = AllocAMMsg()))
  124.         return(FALSE);
  125.  
  126.     Msg->Action = ACT_GETCONTENTS;
  127.     Msg->Username = Username;
  128.     Msg->Mailbox = Mailbox;
  129.  
  130.     AskServer(Msg); /* don't care for results */
  131.     ret = Msg->Number;
  132.  
  133.     FreeMem(Msg,sizeof(struct AMMessage));
  134.     
  135.     return(ret);
  136. }
  137.  
  138. struct Mail *AddItem(ULONG num)
  139. {
  140.     struct AMMessage *Msg;
  141.     struct Mail *New;
  142.  
  143.     if (!(Msg = AllocAMMsg()))
  144.         return(0);
  145.  
  146.     Msg->Action = ACT_ADD_ITEM;
  147.     Msg->Username = Username;
  148.     Msg->Number = num;
  149.  
  150.     AskServer(Msg); /* don't care for results */
  151.  
  152.     New = Msg->NewMail;
  153.  
  154.     FreeMem(Msg,sizeof(struct AMMessage));
  155.  
  156.     return(New);
  157. }
  158.  
  159.  
  160. void MarkRead(ULONG num)
  161. {
  162.     struct AMMessage *Msg;
  163.  
  164.     if (!(Msg = AllocAMMsg()))
  165.         return;
  166.  
  167.     Msg->Action = ACT_MARK_READ;
  168.     Msg->Username = Username;
  169.     Msg->Number = num;
  170.  
  171.     AskServer(Msg); /* don't care for results */
  172.  
  173.     FreeMem(Msg,sizeof(struct AMMessage));
  174. }
  175.  
  176. void MarkUnread(ULONG num)
  177. {
  178.     struct AMMessage *Msg;
  179.  
  180.     if (!(Msg = AllocAMMsg()))
  181.         return;
  182.  
  183.     Msg->Action = ACT_MARK_UNREAD;
  184.     Msg->Username = Username;
  185.     Msg->Number = num;
  186.  
  187.     AskServer(Msg); /* don't care for results */
  188.  
  189.     FreeMem(Msg,sizeof(struct AMMessage));
  190. }
  191.  
  192. void MarkOld(ULONG num)
  193. {
  194.     struct AMMessage *Msg;
  195.  
  196.     if (!(Msg = AllocAMMsg()))
  197.         return;
  198.  
  199.     Msg->Action = ACT_MARK_OLD;
  200.     Msg->Username = Username;
  201.     Msg->Number = num;
  202.  
  203.     AskServer(Msg); /* don't care for results */
  204.  
  205.     FreeMem(Msg,sizeof(struct AMMessage));
  206. }
  207.  
  208. void DeleteItem(ULONG num)
  209. {
  210.     struct AMMessage *Msg;
  211.  
  212.     if (!(Msg = AllocAMMsg()))
  213.         return;
  214.  
  215.     Msg->Action = ACT_DELETE_ITEM;
  216.     Msg->Username = Username;
  217.     Msg->Number = num;
  218.  
  219.     AskServer(Msg); /* don't care for results */
  220.  
  221.     FreeMem(Msg,sizeof(struct AMMessage));
  222. }
  223.  
  224. ULONG NewSeq(void)
  225. {
  226.     struct AMMessage *Msg;
  227.     ULONG seq;
  228.  
  229.     if (!(Msg = AllocAMMsg()))
  230.         return(0);
  231.  
  232.     Msg->Action = ACT_NEW_SEQ;
  233.     Msg->Username = Username;
  234.  
  235.     AskServer(Msg); /* don't care for results */
  236.  
  237.     seq = Msg->Number;
  238.  
  239.     FreeMem(Msg,sizeof(struct AMMessage));
  240.  
  241.     return(seq);
  242. }
  243.  
  244. int NotifyOn(struct MsgPort *NotifyPort)
  245. {
  246.     struct AMMessage *Msg;
  247.     int ret;
  248.  
  249.     if (!(Msg = AllocAMMsg()))
  250.         return(FALSE);
  251.  
  252.     Msg->Action = ACT_NOTIFY_ON;
  253.     Msg->Username = Username;
  254.     Msg->NotifyPort = NotifyPort;
  255.  
  256.     AskServer(Msg); /* don't care for results */
  257.     ret = Msg->Number;
  258.  
  259.     FreeMem(Msg,sizeof(struct AMMessage));
  260.  
  261.     return(ret);
  262. }
  263.  
  264. int NotifyOff(struct MsgPort *NotifyPort)
  265. {
  266.     struct AMMessage *Msg;
  267.     int ret;
  268.  
  269.     if (!(Msg = AllocAMMsg()))
  270.         return(FALSE);
  271.  
  272.     Msg->Action = ACT_NOTIFY_OFF;
  273.     Msg->Username = Username;
  274.     Msg->NotifyPort = NotifyPort;
  275.  
  276.     AskServer(Msg); /* don't care for results */
  277.     ret = Msg->Number;
  278.  
  279.     FreeMem(Msg,sizeof(struct AMMessage));
  280.  
  281.     return(ret);
  282. }
  283.  
  284. char *NewMsgId(char *s)
  285. {
  286.     struct AMMessage *Msg;
  287.  
  288.     if (!(Msg = AllocAMMsg()))
  289.         return(0);
  290.  
  291.     Msg->Action = ACT_NEW_MSGID;
  292.     Msg->MsgId = s;
  293.  
  294.     AskServer(Msg); /* don't care for results */
  295.  
  296.     FreeMem(Msg,sizeof(struct AMMessage));
  297.  
  298.     return(s);
  299. }
  300.  
  301. int CmpVersion(void)
  302. {
  303.     struct AMMessage *Msg;
  304.     int ret;
  305.  
  306.     if (!(Msg = AllocAMMsg()))
  307.         return(FALSE);
  308.  
  309.     Msg->Action = ACT_VERSION;
  310.  
  311.     AskServer(Msg); /* don't care for results */
  312.  
  313.     if (Msg->MsgId) /* very old servers (before 1.7) do not respond to ACT_VERSION */
  314.         ret = !strcmp(Msg->MsgId,AMIGAMAIL_VERSION);
  315.     else
  316.         ret = FALSE;
  317.  
  318.     FreeMem(Msg,sizeof(struct AMMessage));
  319.  
  320.     return(ret);
  321. }
  322.